/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.util;

import java.sql.Connection;
import java.sql.Date;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/**
 *
 * @author GiangLT
 */
public class DBUtil {

    public static Connection getConnection(String JDBCResource) {
        Connection cn = null;
        try {
            Context jndiContext = new InitialContext();
            DataSource source = (DataSource) jndiContext.lookup(JDBCResource);
            cn = source.getConnection();
        } catch (Exception e) {
        }
        return cn;
    }

    public static Connection getConnection(String url, String userName, String password) {
//
        Connection conn = null;
//        try {
//            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
////            String url = "jdbc:oracle:thin:@(description=(address=(host=192.168.11.99)(protocol=tcp)(port=1521))(connect_data=(SERVER = DEDICATED)(service_name=gstt)))";
////            String userName = "avms";
////            String password = "avms";
//            conn = DriverManager.getConnection(url, userName, password);
//        } catch (SQLException ex) {
//        }
        return conn;
//    }
    }

    public static java.sql.Date toSqlDate(java.util.Date date) {
        return new Date(date.getTime());
    }
}
